package com.tn.rtdata.performance;

import org.springframework.beans.factory.BeanNameAware;

/**
 * A bean that represents the definition of a client.
 */
public class ClientDef implements BeanNameAware
{
  private static final String SPACE = " ";

  private String name;
  private String applicationContextLocation;

  /**
   * Creates a new <code>ClientDef</code> initialized with the <code>applicationContextLocation</code>.
   */
  public ClientDef(String applicationContextLocation)
  {
    this.applicationContextLocation = applicationContextLocation;
  }

  /**
   * Returns the application context location.
   */
  public String getApplicationContextLocation()
  {
    return applicationContextLocation;
  }

  /**
   * Returns the display name.
   */
  public String getDisplayName()
  {
    StringBuffer displayName = new StringBuffer();
    boolean firstNumber = true;

    for (int i = 0; i < name.length(); i++)
    {
      String c = name.substring(i, i + 1);
      if (c.matches("\\d"))
      {
        if (firstNumber)
        {
          displayName.append(SPACE);
          firstNumber = false;
        }

        displayName.append(c);
      }
      else
      {
        firstNumber = true;

        if (c.toUpperCase().equals(c))
        {
          displayName.append(SPACE).append(c.toLowerCase());
        }
        else
        {
          displayName.append(c);
        }
      }
    }

    return displayName.toString();
  }

  /**
   * Return the type.
   */
  public String getType()
  {
    return name;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public void setBeanName(String name)
  {
    this.name = name;
  }
}
